import { Component, ViewChildren, ViewChild, ChangeDetectorRef, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import { CacheKeys, CacheProvider } from '../../providers/common/cache';
import { HomeProvider } from '../../providers/home/home';
import { UtilProvider } from '../../providers/common/util';
import { Keyboard } from '@ionic-native/keyboard';
// declare var AMap;
import Swiper from 'swiper';
import { Observable } from 'rxjs/Rx';
declare var BMap;
declare var BMap_Symbol_SHAPE_POINT;
declare var LocationPlugin;
import { HttpClient } from '@angular/common/http';
import { ip } from '../../providers/ip/ip';
import { NativeService } from '../../providers/NativeService';
// @Component({
// 	selector: 'page-home',
// 	templateUrl: 'home.html'
// })
// export class HomePage {
// 	@ViewChild('map2') map_container: ElementRef;
// 	map: any; //地图对象
// 	marker: any; //标记
// 	qq: any;
// 	ww: any;
// 	location: { lng: 120.69847763; lat: 27.92096160; wish: ''};
// 	wishc:any;
// 	data: any;
// 	constructor(private http: HttpClient, private nativeService: NativeService) {
// 		console.log(this.map_container);
// 	}

// 	ionViewDidLoad() {
// 		this.nativeService.getUserLocation().subscribe((res) => {
// 			this.location = res;
// 		});

//         let that = this;
// 		that.wishc="java";
// 		this.location = {
// 			lng: that.location.lng,
// 			lat: that.location.lat,
// 			wish: that.wishc
// 		};
//         alert("地图测试123456");
// 		console.log(this.location);
// 		// console.log(that.nativeService.getUserLocation());
// 		var geolocation = new BMap.Geolocation();
// 		geolocation.getCurrentPosition(
// 			function(r) {
// 				alert("地图测试2");
// 				// alert('您的位置：' + r.point.lng + ',' + r.point.lat);
// 				(that.qq = r.point.lng), (that.ww = r.point.lat);
// 				console.log('1 ' + that.qq, that.ww);
// 				//  point = new BMap.Point(qq, ww);
// 				let map = (that.map = new BMap.Map(that.map_container.nativeElement, { enableMapClick: true })); //创建地图实例
// 				// debugger;
// 				// map.centerAndZoom("广州",17); //设置城市设置中心和地图显示级别
// 				//坐标可以通过百度地图坐标拾取器获取

// 				console.log('2 ' + that.qq, that.ww);

// 				let point = new BMap.Point(that.location.lng, that.location.lat);

// 				map.centerAndZoom(point, 17); //设置中心和地图显示级别

// 				map.addControl(new BMap.MapTypeControl());
// 				// map.setCurrentCity("广州");

// 				let sizeMap = new BMap.Size(10, 80); //显示位置
// 				map.addControl(new BMap.NavigationControl());

// 				map.enableScrollWheelZoom(true); //启动滚轮放大缩小，默认禁用
// 				map.enableContinuousZoom(true); //连续缩放效果，默认禁用

// 				let myIcon = new BMap.Icon('assets/icon/a.jpeg', new BMap.Size(30, 30));
// 				let marker = (that.marker = new BMap.Marker(point, { icon: myIcon }));
// 				map.addOverlay(marker);

// 				that.http.post(ip + 'api/get', that.location, {}).subscribe(
// 					function(data) {
// 						console.log(data);
// 						// alert(data.data.token);
// 						let i;
// 						that.data = data;
// 						for (i in that.data.data) {
// 							//alert(that.data.data[i]._source.longitude+"--"+that.data.data[i]._source.latitude)
// 							let point = new BMap.Point(
// 								that.data.data[i]._source.longitude,
// 								that.data.data[i]._source.latitude
// 							);
// 							let marker = (that.marker = new BMap.Marker(point, { icon: myIcon }));
// 							// let marker = (that.marker = new BMap.Marker(point, { icon: "../../assets/imgs/yuan.png" }));
// 							map.addOverlay(marker);
// 						}
// 					},
// 					function(err) {
// 						console.log(err);
// 					}
// 				);
// 			},
// 			{ enableHighAccuracy: true }
// 		);
// 	}
// }
declare var AMap;

@Component({
		selector: 'page-home',
		templateUrl: 'home.html'
	})
	export class HomePage {
	// gaodemap

	@ViewChild('map2') map_container2: ElementRef;
	map: any;//地图对象

	constructor() {
	}

	ionViewDidEnter() {
		this.load();
	}
	load() {
		this.map = new AMap.Map(this.map_container2.nativeElement, {
			view: new AMap.View2D({//创建地图二维视口
				center: [113.23, 23.16],
				zoom: 16, //设置地图缩放级别
				rotateEnable: true,
				showBuildingBlock: true
			})
		});
	}

}
